home *** CD-ROM | disk | FTP | other *** search
- Path: brookes.ac.uk!news
- From: Krunchie <95155580@brookes.ac.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Kind of an annoying question...
- Date: 15 Mar 1996 04:07:00 GMT
- Organization: Digital Dynamics Unlimited
- Message-ID: <4iaqd4$l70@cs3.brookes.ac.uk>
- References: <4hvrio$c4k@lastactionhero.rs.itd.umich.edu>
- NNTP-Posting-Host: rm003a2e.brookes.ac.uk
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
-
- speng@stimpy.us.itd.umich.edu (Steve Palmer Peng) wrote:
- >I'm wondering, just what function in C allows me to enter a character
- >from the keyboard, and it automatically executes the command I designate
- >that character to. For instance, I have something like,
- >
- >printf("Enter Y or N:");
- >
- >and I want the command after the printf statement to wait for input
- >from the keyboard, but once someone enters a Y or an N, the next line of
- >code is executed, without hitting enter. Does anyone know how? It would
- >be greatly appreciated if someone could help me out here...
- >
- >Steve
- >
- >
- Here is an example of how this can easily be achieved:
-
- int main(void)
- {
- char choice;
- printf("Do you want to drop an H-Bomb on Iraq (Y or N)");
- choice=getch(); /* vital line */
- if(choice=='Y') start_war();
- /* rest of program */
- return 0;
- }
-
- int start_war(void)
- {
- /* start war function */
- return 0;
- }
-
-
- Regards
-
- Krunchie
- Digital Dynamics - Dynamic Software solutions for a dynamic world.
- 95155580@brookes.ac.uk
-
-